package com.myCinema.dao.impl;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

import com.myCinema.dao.HibernateUtil;
import com.myCinema.entity.Category;

public class CategoryDaoImpl{
	public List<Category> getList(){
		Session sess = null;
		try{
			sess = HibernateUtil.openSession();
			Query q = sess.createQuery("from Category");
			return q.list();
		}finally{
			sess.close();
		}
	}
	
	public void delete(int id){
		Session sess = null;
		try{
			sess = HibernateUtil.openSession();
			Transaction tx = sess.beginTransaction();
			Category c = (Category)sess.get(Category.class, id);
			sess.delete(c);
			tx.commit();
		}finally{
			sess.close();
		}
	}

	public void save(Category c) {
		Session sess = null;
		try{
			sess = HibernateUtil.openSession();
			Transaction tx = sess.beginTransaction();
			sess.save(c);
			tx.commit();
		}finally{
			sess.close();
		}
	}
	

}
